package com.itfitness.jiaguplugin

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import java.io.File
import javax.inject.Inject

/**
 *
 * @ProjectName:    AndroidTest
 * @Package:        com.itfitness.jiaguplugin
 * @ClassName:      JiaguTask
 * @Description:     java类作用描述
 * @Author:         itfitness
 * @CreateDate:     2021/12/18 16:38
 * @UpdateUser:     更新者：
 * @UpdateDate:     2021/12/18 16:38
 * @UpdateRemark:   更新说明：
 */
open class JiaguTask @Inject constructor(
    val apkFile: File,
    val jiaguParams: JiaguParams
) : DefaultTask() {
    init {
        //给Task创建一个分组
        group = "jiagu"
    }

    @TaskAction
    fun jiagu(){
        //登录360加固
        project.exec {
            it.commandLine("java","-jar",jiaguParams.jiaguJarFilePath,"-login",jiaguParams.userName,jiaguParams.password)
        }
        //导入签名文件
        project.exec {
            it.commandLine("java","-jar",jiaguParams.jiaguJarFilePath,"-importsign",
                jiaguParams.keystorePath,jiaguParams.keystorePassword,jiaguParams.alias,jiaguParams.aliasPassword)
        }
        //进行加固，并且自动签名
        project.exec {
            it.commandLine("java","-jar",jiaguParams.jiaguJarFilePath,"-jiagu",
                apkFile.absolutePath,apkFile.parent,"-autosign")
        }
    }
}